const React = require('react');
//组件
class Index extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            count: 0
        }
    }
    handleClick = () => {
        this.setState({
            count: this.state.count + 1
        })
    }
    render() {
        return <h1 onClick={this.handleClick}>{this.state.count}</h1>
    }
}
const Http = require('http')
const { renderToString} = require('react-dom/server')
console.log(renderToString(<Index />)) // 直出html字符串
Http.createServer((request, response) => {
    response.writeHead(200, {
        'Content-type': 'text/html'
    })
    const html = renderToString(<Index />)
    response.end(`<!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>传统 ssr</title>
        </head>
        <body>
            <div id="root">
               ${html}
            </div>
        </body>
        </html>
    `)
}).listen(9091)